<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/6/3
  Time: 11:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List, java.util.Map, java.util.Collections, java.util.Comparator" %>
<%@ page import="com.spider.sql.pojo.User" %>
<%@ page import="com.spider.sql.pojo.InjectionData" %>
<html>
<head>
    <title>报告</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="jumbotron jumbotron-fluid text-center bg-primary text-white">
    <div class="container">
        <h1 class="display-4">报告</h1>
        <p class="lead">以下是解析数据的报告</p>
    </div>
</div>

<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-10">
            <div class="card mb-4">
                <div class="card-body">
                    <h4 class="card-title">爬虫记录：</h4>
                    <%
                        List<Map<String, Object>> spiderData = (List<Map<String, Object>>) session.getAttribute("spiderData");
                        if (spiderData != null) {
                            Collections.sort(spiderData, new Comparator<Map<String, Object>>() {
                                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                                    return ((String) o2.get("timestamp")).compareTo((String) o1.get("timestamp"));
                                }
                            });
                            for (Map<String, Object> record : spiderData) {
                                Map<String, String> parsedData = (Map<String, String>) record.get("parsedData");
                                String timestamp = (String) record.get("timestamp");
                                out.println("<div class='card mb-2'><div class='card-body'>");
                                out.println("<h5 class='card-title'>记录时间: " + timestamp + "</h5>");
                                out.println("<div class='alert alert-info' role='alert'>解析到的内容：</div>");
                                out.println("<p class='card-text'>标题: " + parsedData.get("title") + "</p>");
                                out.println("<p class='card-text'>H1: " + parsedData.get("h1") + "</p>");
                                out.println("<p class='card-text'>H2: " + parsedData.get("h2") + "</p>");
                                out.println("<p class='card-text'>H3: " + parsedData.get("h3") + "</p>");
                                out.println("<p class='card-text'>段落: " + parsedData.get("p") + "</p>");
                                out.println("<p class='card-text'>图片链接: " + parsedData.get("img") + "</p>");
                                out.println("</div></div>");
                            }
                        } else {
                            out.println("<p>没有爬虫记录。</p>");
                        }
                    %>
                </div>
            </div>

            <div class="card mb-4">
                <div class="card-body">
                    <h4 class="card-title">SQL注入记录：</h4>
                    <%
                        List<InjectionData> injectionDataList = (List<InjectionData>) session.getAttribute("injectionDataList");
                        if (injectionDataList != null) {
                            Collections.sort(injectionDataList, new Comparator<InjectionData>() {
                                public int compare(InjectionData o1, InjectionData o2) {
                                    return o2.getTimestamp().compareTo(o1.getTimestamp());
                                }
                            });
                            for (InjectionData data : injectionDataList) {
                                String endpoint = data.getEndpoint();
                                String timestamp = data.getTimestamp();
                                String username = data.getUsername();
                                String password = data.getPassword();
                                Object result = data.getResult();
                                out.println("<div class='card mb-2'><div class='card-body'>");
                                out.println("<h5 class='card-title'>记录时间: " + timestamp + "</h5>");
                                out.println("<div class='alert alert-info' role='alert'>注入接口：" + endpoint + "</div>");
                                out.println("<div class='alert alert-info' role='alert'>注入参数：</div>");
                                out.println("<p class='card-text'>用户名：" + username + "</p>");
                                if (password != null) {
                                    out.println("<p class='card-text'>密码：" + password + "</p>");
                                }
                                out.println("<div class='alert alert-info' role='alert'>结果：</div>");
                                if (result instanceof User) {
                                    User user = (User) result;
                                    out.println("<p class='card-text'>用户ID：" + user.getId() + "</p>");
                                    out.println("<p class='card-text'>用户名：" + user.getUsername() + "</p>");
                                    out.println("<p class='card-text'>密码：" + user.getPassword() + "</p>");
                                } else if (result instanceof List) {
                                    List<User> userList = (List<User>) result;
                                    for (User user : userList) {
                                        out.println("<p class='card-text'>用户ID：" + user.getId() + "</p>");
                                        out.println("<p class='card-text'>用户名：" + user.getUsername() + "</p>");
                                        out.println("<p class='card-text'>密码：" + user.getPassword() + "</p>");
                                    }
                                }
                                out.println("</div></div>");
                            }
                        } else {
                            out.println("<p>没有SQL注入记录。</p>");
                        }
                    %>
                </div>
            </div>


        </div>
    </div>
</div>

<footer class="footer bg-dark text-white text-center mt-5">
    <div class="container">
        <p class="mb-0 py-3">&copy; 2024 基于SSM实现爬虫和Sql注入的Web应用. 保留所有权利.</p>
    </div>
</footer>
</body>
</html>
